﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace 运算符
{
    class Program
    {
        //算数运算符
        static void Main1(string[] args)
        {
            int a = 10;
            int b = 3;
            Console.WriteLine(a / b);//没有小数点
            Console.WriteLine(a / (float)b);//有小数点
            Console.WriteLine(a % b);//1 取余一般用来判断整除1
            int c = 2;
            Console.WriteLine(c++);//2

            int d = 5;
            int e = d++ + 2;
            Console.WriteLine(e);//7
            Console.WriteLine(d);
        }
        //关系运算符
        static void Main2(string[] args)
        {
            int a = 5;
            int b = 6;
            int c = 5;
            Console.WriteLine(a > b);

            Console.WriteLine(a == c);

            Console.WriteLine(a != b);

            bool d = a <= b;
        }
        //赋值运算符
        static void Main3(string[] args)
        {
            //赋值就是复制
            int a = 5;
            int b = a;

            string s = "你好";
            string s1 = s;

            //累加符号
            int c = 1;
             c += 2;// 等同于 c = c + 2;
            Console.WriteLine(c);//3
        }
        //逻辑运算符
        static void Main4(string[] args)
        {
            int a = 7;
            int b = -12;
            int c = a + b;
          
            Console.WriteLine(a > b && a < c);//false
            Console.WriteLine(a>b||a<c);//true
            Console.WriteLine(  !(a>b));//false

            Console.WriteLine("请输入密码:");
            string input = Console.ReadLine();
            if (input=="123456")
            {
                Console.WriteLine("密码正确");
            }
            else
            {
                Console.WriteLine("密码错误");
            }
        }

        //位运算符
        static void Main5(string[] args)
        {
            // &  同为1则为1
            int a = 5;//0000 0101
            int b = 6;//0000 0110
            Console.WriteLine(a&b);//0000 0100        4

            // | 有1个为1则为1
            Console.WriteLine(a|b);//0000 0111       7

            // ~  变1为0  变0为1
            Console.WriteLine(~-1);//0

            //移位
            //左移 右边补0
            Console.WriteLine(1<<2);//1往左移2位得到4
            Console.WriteLine(1<<16);//65536
            //右移  左边补符号位
            Console.WriteLine(-1>>1);//-1

            //异或  两个不一样则为1 
            Console.WriteLine(a^b);//3
        }

        //三元运算符  (三元表达式)
        static void Main6(string[] args)
        {
            int a = 5;
            int b = 6;
            int c = a > b ? 10 : 20;
            Console.WriteLine(c);//20
        }
        static void Main(string[] args)
        {
            Console.WriteLine("请输入成绩:");
            float score = float.Parse( Console.ReadLine());
            string leve =
                score >= 90 ? "优秀" :
                score >= 70 ? "良好" :
                score >= 60 ? "及格" :
                "不及格";
            Console.WriteLine(leve);
        }
    }
}
